package com.zzyl.mapper;

import com.github.pagehelper.Page;
import com.zzyl.entity.Reservation;
import com.zzyl.vo.ReservationVo;
import com.zzyl.vo.TimeCountVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface CustomerReservationMapper {
    // 插入操作
    int insert(Reservation reservation);

    // 更新操作
    int update(Reservation reservation);

    // 删除操作
    int delete(Long id);

    // 查询操作
    Reservation selectById(Long id);

    // 查询所有预约信息
    List<Reservation> selectAll();

    @Select("select COUNT(*) from reservation as r where status=2  and create_by = #{userId} and time between #{begin} and #{end} GROUP BY create_by ")
    Integer selectByCreateId(Long userId,LocalDateTime begin,LocalDateTime end);


    @Select("select count(*) as count,time from reservation as r where time between #{begin} and #{end} group by time")
    List<TimeCountVo> queryCountByTime(LocalDateTime begin, LocalDateTime end);

    Page<ReservationVo> selectPage(Integer status ,Long userId);

    @Select("select count(*) from reservation as r where r.time =#{time}")
    Integer selectByTime(LocalDateTime time);

    void updateByList(List<Reservation> reservationList);

    @Update("update reservation  set status=3 where time <  now() and status = 0 ")
    void updateStatus();
}